package org.example.api.Blog;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.domain.Blog;
import org.springframework.stereotype.Service;

/**
 * @author Aaron
 * @since 2020/12/25 16:46
 * <p>描述：</p>
 */
@Slf4j
@Service
public class FeignBlogServiceImpl implements FallbackFactory<FeignBlogService> {

    @Override
    public FeignBlogService create(Throwable throwable) {
        return id -> {
            // 日志最好放在各个 fallback 方法中，而不要直接放在 create 方法中。
            // 否则在引用启动时就会打印日志
            log.info("fallback; reason was:{}", throwable);
            Blog blog = new Blog();
            blog.setId(-1L);
            blog.setTitle("默认标题");
            return blog;
        };
    }


}
